const {common: common} = require("../../../../common/common");

const {getTouchData: getTouchData} = require("../../../../utils/util");

// leaderPerson/pages/groupDragon/PasteDragon/past-dragon.js
Page({
    /**
   * 页面的初始数据
   */
    data: {
        type_active: 1,
        tabs: [ {
            label: "我的群接龙",
            value: 1
        }, {
            label: "平台群接龙",
            value: 2
        } ],
        lists: [],
        page: 1
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad(options) {},
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow() {
        this.getList();
    },
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom() {
        this.getList();
    },
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage() {},
    changeTab: function(e) {
        let value = e.currentTarget.dataset.value;
        this.setData({
            type_active: value,
            page: 1
        });
        // wx.showLoading({
        //   title: "请稍候..."
        // });
                this.getList();
    },
    /**
   * 复制群接龙
   */
    confirm: function(e) {
        let id = e.detail.value;
        wx.navigateTo({
            url: `/leaderPerson/pages/groupDragon/Create/create?copy_id=${id}&opetype=3`
        });
    },
    /**
   * 获取列表
   */
    getList: function() {
        let that = this;
        console.log(that.data.page);
        wx.showLoading({
            title: "加载中..."
        });
        common.request({
            endpoint: "Leader/leader-group/copy-list",
            method: "post",
            data: {
                flag: that.data.type_active,
                page: that.data.page
            },
            success: res => {
                wx.hideLoading();
                if (res.code == 0) {
                    let lists = res.extra;
                    lists = that.data.page == 1 ? lists : that.data.lists.concat(lists);
                    that.setData({
                        lists: lists,
                        page: that.data.page + 1
                    });
                }
            },
            fail: res => {
                wx.hideLoading();
            }
        });
    }
});